#!/bin/bash

# Slackware build script for picospeaker

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=picospeaker
VERSION=${VERSION:-0.6.2}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
chmod 644 *
chmod 755 . $PRGNAM

# python3 support and short language names (de => de_DE).
patch -p1 < $CWD/36273f9d_and_d6a7a01.diff

# actually use python3. doesn't really matter, but someday python2 might
# really go away...
sed -i '1s,python,python3,' $PRGNAM

PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKG/usr/{bin,man/man1} $PKGDOC
cp -a $PRGNAM $PKG/usr/bin
gzip -9c < $CWD/$PRGNAM.1 > $PKG/usr/man/man1/$PRGNAM.1.gz

mkdir -p $PKGDOC
fmt -s README > $PKGDOC/README  # line breaks, please.
cp -a UNLICENSE $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
